//
//  VisitorTableViewController.swift
//  01-界面搭建
//
//  Created by Apple on 15/11/3.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    //用户登录标记
    private var userLogin =  UserAccountViewModel.shardViewModel.userLogin
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //在这里设置，只有当控件创建之后才会执行，所以，启动程序一开始颜色不会变
        //UINavigationBar.appearance().tintColor = UIColor.orangeColor()
    }
    /// 访客视图
    var visitorView: VisitorView?
    override func loadView() {
        userLogin ? super.loadView() : setUpVisitorView()
    }
    private func setUpVisitorView () {
        visitorView =  VisitorView()
        // 设置代理
        //visitorView?.delegate = self
        view = visitorView
        //注册
        visitorView?.registerButton .addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        //登录
        visitorView?.LoginButton .addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style:.Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style:.Plain, target: self, action: "visitorViewDidLogin")
        
    }
    
}
//MARK: - 监听方法
extension VisitorTableViewController {
    func visitorViewDidRegister() {
        print("注册")
    }
    func visitorViewDidLogin() {
        //modal跳转控制器
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
}